<!--
@name:targetDialog
@author:Zhenglei
@date:11:27
@description:targetDialog
@update:2022/5/1911:27
-->
<template>
  <div>
    <el-dialog :title="title"
               :visible.sync="visible"
               :before-close="modalClose"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               width="90%">
      <el-form :model="submitData"
               label-position="right"
               ref="formModelRef"
               :rules='rules'
               label-width="150px">
        <el-form-item label="服务名称："
                      prop="name">
          <el-input v-model="submitData.name"
                    clearable
                    class="w-300"
                    placeholder="请输入服务名称"></el-input>
        </el-form-item>
        <el-form-item label="所属分类："
                      prop="healthRiskTypeId">
          <el-select v-model="submitData.healthRiskTypeId"
                     clearable
                     class="w-300"
                     placeholder="请选择所属分类">
            <el-option v-for="item in healthRiskTypeList"
                       :key="item.id"
                       :label="item.name"
                       :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签："
                      prop="label">
          <el-input v-model="submitData.label"
                    clearable
                    class="w-300"
                    placeholder="请输入标签"></el-input>
        </el-form-item>

        <el-form-item label="适应病症：">
          <el-tree
            :data="slowList"
            show-checkbox
            node-key="id"
            :default-checked-keys="defaultCheckedKeys"
            :props="defaultProps"
            @check="handleCheckChange">
          </el-tree>        </el-form-item>

        <el-form-item label="列表图片：" class="is-required">
          <el-upload :action="fileLogoUploadAction"
                     class="avatar-uploader"
                     :show-file-list="false"
                     accept=".JPG, .PNG, .JPEG,.jpg, .png, .jpeg"
                     :before-upload="beforeAvatarUpload"
                     :on-success="uploadLogoSuccess">
            <img v-if="submitData.imageUrl" :src="submitData.imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"
               style="font-size: 28px;color: #8c939d;width: 148px;height: 148px;line-height: 148px;text-align: center;"></i>
          </el-upload>

        </el-form-item>
        <el-form-item label="详情图片：" class="is-required">
          <el-upload multiple
                     :limit='6'
                     :action="fileLogoUploadAction"
                     accept=".JPG, .PNG, .JPEG,.jpg, .png, .jpeg"
                     list-type="picture-card"
                     :on-success="handlePictureCardPreview"
                     :file-list='detailImageList'
                     :on-exceed='onexceed'
                     :on-remove='onremove'
                     :before-upload="beforeAvatarUpload">
            <i class="el-icon-plus avatar-uploader-icon" style=""></i>
          </el-upload>
        </el-form-item>
        <!--  服务选项      -->
        <el-form-item label="服务选项：" class="is-required">
          <el-button type="success"
                     @click="handleOption('addItem')">新 增 一 项
          </el-button>
          <element-table class="mt-20"
                         :columns="columnsServiceItem"
                         :is-show-null="false"
                         :data="submitData.itemList">
            <template v-slot:price="{row}">
              <el-input
                type="number"
                v-model="row.price"
                @blur="hadnleInput"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:num="{row}">
              <el-input
                type="number"
                v-model="row.num"
                @blur="hadnleInput"
                placeholder="请输入数量"/>
            </template>
            <template v-slot:unit="{row}">
              <el-select v-model="row.unit"
                         @change="hadnleInput"
                         placeholder="请选择单位">
                <el-option label="小时"
                           :value="1"/>
                <el-option label="次"
                           :value="2"/>
              </el-select>
            </template>
            <template v-slot:detectFee="{row}">
              <el-input
                type="number"
                v-model="row.detectFee"
                placeholder="请输入检测分成费用"/>
            </template>
            <template v-slot:extendFee="{row}">
              <el-input
                type="number"
                v-model="row.extendFee"
                placeholder="请输入推广分成费用"/>
            </template>


            <template v-slot:option="{row,index}">
              <el-button type="primary"
                         @click="handleOption('detectConfig', row,index)">配置检测项
              </el-button>
              <el-button type="danger"
                         @click="handleOption('delItem', index)">删除
              </el-button>
            </template>
          </element-table>
        </el-form-item>
        <el-form-item label="标配服务："
                      prop="standardService">
          <el-input v-model="submitData.standardService"
                    maxlength="500"
                    show-word-limit
                    type="textarea"
                    class="w-400"
                    placeholder="请输入标配服务"/>
        </el-form-item>

        <el-form-item label="服务医院：" prop="hospitalList">
          <el-select v-model="submitData.hospitalList"
                     value-key="hospitalId"
                     filterable
                     multiple
                     remote
                     clearable
                     reserve-keyword
                     placeholder="请输入医院"
                     :remote-method="searchMethod"
                     :loading="searchLoading"
                     class="w-300">
            <el-option v-for="item in hospitals"
                       :key="item.hospitalId"
                       :label="item.name"
                       :value="item">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否重点合作医院："
                      prop="emphasisHospital" >
          <el-checkbox v-for="(item, index) in submitData.hospitalList"
                       :label="item.hospitalId"
                       :checked="item.emphasisHospital===1?true:false"
                       @change="value=>{checkboxItem(value,index, item)}"
                       :key="item.hospitalId">{{ item.name }}
          </el-checkbox>

        </el-form-item>
        <el-form-item label="监测范围："
                      prop="rangeContent">
          <el-input v-model="submitData.rangeContent"
                    maxlength="500"
                    show-word-limit
                    type="textarea"
                    autosize
                    class="w-400"
                    placeholder="请输入可适用的健康风险筛查与监测范围"/>
        </el-form-item>
        <el-form-item label="分成设置："
                      prop="split">
          <el-radio-group v-model="submitData.split">
            <el-radio :label="0">报告不拆分</el-radio>
            <el-radio :label="1">报告拆分</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="特殊筛查项目："
                      prop="specialItem"
                      v-if="submitData.split === 0">
          <el-radio-group v-model="submitData.specialItem">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="执行分析复核流程："
                      prop="specialItem"
                      v-if="submitData.split === 0 && submitData.specialItem === 1">
          <el-radio-group v-model="submitData.reCheck">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="分析分成：" v-if="submitData.split === 0 && submitData.reCheck === 1">
          <el-radio-group v-model="analyseType">
            <el-radio-button :label="0">医 师</el-radio-button>
            <el-radio-button :label="2">技 师</el-radio-button>
            <el-radio-button :label="7">检验师</el-radio-button>
          </el-radio-group>
          <!--          医师-->
          <element-table class="mt-20"
                         v-if="analyseType==0"
                         :columns="columnsAnalyseDoctor"
                         :is-show-null="false"
                         :data="analyseDoctorList">
            <template v-slot:priceSku="{row}">
              <el-tag>{{ row.priceSku }}</el-tag>
            </template>
            <template v-slot:price1="{row}">
              <el-input
                v-model="row.price1"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price2="{row}">
              <el-input
                v-model="row.price2"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price3="{row}">
              <el-input
                v-model="row.price3"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price4="{row}">
              <el-input
                v-model="row.price4"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price5="{row}">
              <el-input
                v-model="row.price5"
                placeholder="请输入价格"/>
            </template>

          </element-table>
          <!--          技师-->
          <element-table class="mt-20"
                         v-if="analyseType==2"
                         :columns="columnsAnalyseTechnician"
                         :is-show-null="false"
                         :data="analyseTechnicianList">
            <template v-slot:priceSku="{row}">
              <el-tag>{{ row.priceSku }}</el-tag>
            </template>
            <template v-slot:price1="{row}">
              <el-input
                v-model="row.price1"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price2="{row}">
              <el-input
                v-model="row.price2"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price3="{row}">
              <el-input
                v-model="row.price3"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price4="{row}">
              <el-input
                v-model="row.price4"
                placeholder="请输入价格"/>
            </template>
          </element-table>
          <!--          检验师-->
          <element-table class="mt-20"
                         v-if="analyseType==7"
                         :columns="columnsAnalyseDocimaster"
                         :is-show-null="false"
                         :data="analyseDocimasterList">
            <template v-slot:priceSku="{row}">
              <el-tag>{{ row.priceSku }}</el-tag>
            </template>
            <template v-slot:price1="{row}">
              <el-input
                v-model="row.price1"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price2="{row}">
              <el-input
                v-model="row.price2"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price3="{row}">
              <el-input
                v-model="row.price3"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price4="{row}">
              <el-input
                v-model="row.price4"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price5="{row}">
              <el-input
                v-model="row.price5"
                placeholder="请输入价格"/>
            </template>
          </element-table>
        </el-form-item>

        <el-form-item label="复核分成：" v-if="submitData.split === 0 && submitData.reCheck === 1">
          <el-radio-group v-model="reCheckType">
            <el-radio-button :label="0">医 师</el-radio-button>
            <el-radio-button :label="2">技 师</el-radio-button>
            <el-radio-button :label="7">检验师</el-radio-button>
          </el-radio-group>
          <!--          医师-->
          <element-table class="mt-20"
                         v-if="reCheckType==0"
                         :columns="columnsReCheckDoctor"
                         :is-show-null="false"
                         :data="reCheckDoctorList">
            <template v-slot:priceSku="{row}">
              <el-tag>{{ row.priceSku }}</el-tag>
            </template>
            <template v-slot:price1="{row}">
              <el-input
                v-model="row.price1"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price2="{row}">
              <el-input
                v-model="row.price2"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price3="{row}">
              <el-input
                v-model="row.price3"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price4="{row}">
              <el-input
                v-model="row.price4"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price5="{row}">
              <el-input
                v-model="row.price5"
                placeholder="请输入价格"/>
            </template>

          </element-table>
          <!--          技师-->
          <element-table class="mt-20"
                         v-if="reCheckType==2"
                         :columns="columnsReCheckTechnician"
                         :is-show-null="false"
                         :data="reCheckTechnicianList">
            <template v-slot:priceSku="{row}">
              <el-tag>{{ row.priceSku }}</el-tag>
            </template>
            <template v-slot:price1="{row}">
              <el-input
                v-model="row.price1"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price2="{row}">
              <el-input
                v-model="row.price2"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price3="{row}">
              <el-input
                v-model="row.price3"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price4="{row}">
              <el-input
                v-model="row.price4"
                placeholder="请输入价格"/>
            </template>
          </element-table>
          <!--          检验师-->
          <element-table class="mt-20"
                         v-if="reCheckType==7"
                         :columns="columnsReCheckDocimaster"
                         :is-show-null="false"
                         :data="reCheckDocimasterList">
            <template v-slot:priceSku="{row}">
              <el-tag>{{ row.priceSku }}</el-tag>
            </template>
            <template v-slot:price1="{row}">
              <el-input
                v-model="row.price1"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price2="{row}">
              <el-input
                v-model="row.price2"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price3="{row}">
              <el-input
                v-model="row.price3"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price4="{row}">
              <el-input
                v-model="row.price4"
                placeholder="请输入价格"/>
            </template>
            <template v-slot:price5="{row}">
              <el-input
                v-model="row.price5"
                placeholder="请输入价格"/>
            </template>
          </element-table>
        </el-form-item>

        <el-form-item label="特别说明："
                      prop="specialNote">
          <el-input v-model="submitData.specialNote"
                    maxlength="500"
                    :rows="4"
                    type="textarea"
                    autosize
                    autocomplete="off"
                    show-word-limit
                    class="w-400"
                    placeholder="请输入特别说明"></el-input>
        </el-form-item>
        <el-form-item label="医学知识：">
          <el-button type="success"
                     @click="handleOption('addMedicinel')">新 增 一 项
          </el-button>
          <element-table class="mt-20"
                         :columns="columnsMedicine"
                         :is-show-null="false"
                         :data="medicineList">
            <template v-slot:name="{row}">
              <el-input
                v-model="row.name"
                placeholder="请输入项目名称"/>
            </template>

            <template v-slot:clinicalWorth="{row}">
              <el-input v-model="row.clinicalWorth"
                        maxlength="500"
                        :rows="4"
                        type="textarea"
                        autocomplete="off"
                        show-word-limit
                        placeholder="请输入临床意义"/>
            </template>
            <template v-slot:imageUrl="{row,index}">
              <el-upload :action="fileLogoUploadAction"
                         class="avatar-uploader"
                         :show-file-list="false"
                         accept=".JPG, .PNG, .JPEG,.jpg, .png, .jpeg"
                         :before-upload="beforeAvatarUpload"
                         :on-success="uploadMedicineSuccess">
                <img v-if="row.imageUrl" :src="row.imageUrl" class="avatar" @click="handleIndex(index)">
                <i v-else class="el-icon-plus avatar-uploader-icon" @click="handleIndex(index)"
                   style="font-size: 28px;color: #8c939d;width: 148px;height: 148px;line-height: 148px;text-align: center;"></i>
              </el-upload>

            </template>
            <template v-slot:option="{row,index}">
              <el-button type="danger"
                         @click="handleOption('delMedicinel',index)">删 除
              </el-button>
            </template>

          </element-table>

        </el-form-item>

        <el-form-item label="医学链接：">
          <el-button type="success"
                     @click="handleOption('addMedicinelLink')">新 增 一 项
          </el-button>
          <element-table class="mt-20"
                         :columns="columnsMedicineLink"
                         :is-show-null="false"
                         :data="medicineLinkList">
            <template v-slot:name="{row}">
              <el-input
                v-model="row.name"
                placeholder="请输入链接名称"/>
            </template>

            <template v-slot:linkUrl="{row}">
              <el-input v-model="row.linkUrl"
                        maxlength="500"
                        :rows="4"
                        type="textarea"
                        autocomplete="off"
                        show-word-limit
                        placeholder="请输入链接地址"/>
            </template>
            <template v-slot:option="{row,index}">
              <el-button type="danger"
                         @click="handleOption('delMedicinelLink',index)">删 除
              </el-button>
            </template>
          </element-table>

        </el-form-item>
        <el-form-item label="复核医生：" v-if="submitData.reCheck === 1">

          <element-table
            :columns="columnsDoctors"
            :data="submitData.hospitalList">

            <template v-slot:nickName="{row}">
              <el-tag v-for="(item,idx) in row.doctorDtos" :key="idx" style="margin-left: 5px">{{ item.nickName }}
              </el-tag>
            </template>
            <template v-slot:option="{row,index}">
              <el-button type="primary"
                         @click="handleOption('editDoctor',row,index)">编 辑
              </el-button>
            </template>
          </element-table>

        </el-form-item>

        <el-form-item label="购买服务后，是否填写健康服务号："
                      label-width="240px">
          <el-radio-group v-model="submitData.isInvitationCode">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>

      </el-form>
      <p align="center">
        <el-button type="primary"
                   @click="handleOption('submit', null)">确 认
        </el-button>
        <el-button @click="modalClose"
                   style="margin-left: 8px">取 消
        </el-button>
      </p>

    </el-dialog>
    <doctor-dialog v-if="showDoctorDialog"
                   :doctorData='doctorData'
                   :visible.sync="showDoctorDialog"
                   @handleResultList="handleResultList"/>

    <detect-dialog v-if="showDetectConfigDialog"
                   :detectListData='detectListData'
                   :visible.sync="showDetectConfigDialog"
                   @handleResultDetect="handleResultDetect"/>
  </div>
</template>

<script>
import ElementTable from "../../../../base/ElementTable";
import editDorctorDialog from "./editDorctorDialog";
import detectConfigDialog from "./detectConfigDialog";

export default {
  name: "targetDialog",
  props: {
    dataObj: {
      type: Object,
      default: {}
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      title: '新 增',
      showDoctorDialog: false,
      showDetectConfigDialog: false,
      slowList: [],
      defaultCheckedKeys: [],
      defaultProps: {
        label: "themeName",
        children: "children"
      },
      doctorData: {},
      detectListData: {},
      submitData: {
        id: '',
        name: '',
        healthRiskTypeId: '',
        type: 1,
        label: '',
        imageUrl: '',
        detailImage: '',
        itemList: [],
        standardService: '',
        hospitalList: [],
        rangeContent: '',
        split: 0,
        specialItem: 0,
        reCheck: 0,
        specialNote: '',
        loreList: [],
        isInvitationCode: 0,
        healthCheckPackageThemes:[]
      },
      detailImageList: [],
      fileLogoUploadAction: this.api.appUpgradeUpload.url,
      healthRiskTypeList: [],
      columnsServiceItem: [
        {
          label: '价格（元）',
          prop: 'price',
          align: "center",
          isSlot: true
        }, {
          label: '数量',
          prop: 'num',
          align: "center",
          isSlot: true

        }, {
          label: '单位',
          prop: 'unit',
          align: "center",
          isSlot: true

        }, {
          label: '检测分成费用',
          prop: 'detectFee',
          align: "center",
          isSlot: true
        }, {
          label: '推广分成费用',
          prop: 'extendFee',
          align: "center",
          isSlot: true
        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true,
        }
      ],
      searchLoading: false,
      hospitals: [],

      analyseType: 0,//分析分成类型
      columnsAnalyseDoctor: [//医生
        {
          label: '价格（元）',
          prop: 'priceSku',
          align: "center",
          isSlot: true
        }, {
          label: '主任医师',
          prop: 'price1',
          align: "center",
          isSlot: true

        }, {
          label: '副主任医师',
          prop: 'price2',
          align: "center",
          isSlot: true

        }, {
          label: '主治医师',
          prop: 'price3',
          align: "center",
          isSlot: true
        }, {
          label: '住院医师',
          prop: 'price4',
          align: "center",
          isSlot: true
        }, {
          label: '公共卫生执业医师',
          prop: 'price5',
          align: 'center',
          isSlot: true,
        }
      ],
      columnsAnalyseTechnician: [//技师
        {
          label: '价格（元）',
          prop: 'priceSku',
          align: "center",
          isSlot: true
        }, {
          label: '主任技师',
          prop: 'price1',
          align: "center",
          isSlot: true

        }, {
          label: '副主任技师',
          prop: 'price2',
          align: "center",
          isSlot: true

        }, {
          label: '主管技师',
          prop: 'price3',
          align: "center",
          isSlot: true
        }, {
          label: '技师',
          prop: 'price4',
          align: "center",
          isSlot: true
        }
      ],
      columnsAnalyseDocimaster: [//技师
        {
          label: '价格（元）',
          prop: 'priceSku',
          align: "center",
          isSlot: true
        }, {
          label: '主任检验师',
          prop: 'price1',
          align: "center",
          isSlot: true

        }, {
          label: '副主任检验师',
          prop: 'price2',
          align: "center",
          isSlot: true

        }, {
          label: '主管检验师',
          prop: 'price3',
          align: "center",
          isSlot: true
        }, {
          label: '检验师',
          prop: 'price4',
          align: "center",
          isSlot: true
        }, {
          label: '检验士',
          prop: 'price5',
          align: "center",
          isSlot: true
        }
      ],
      analyseDoctorList: [],
      analyseTechnicianList: [],
      analyseDocimasterList: [],

      reCheckType: 0,//复核分成类型
      columnsReCheckDoctor: [//医生
        {
          label: '价格（元）',
          prop: 'priceSku',
          align: "center",
          isSlot: true
        }, {
          label: '主任医师',
          prop: 'price1',
          align: "center",
          isSlot: true

        }, {
          label: '副主任医师',
          prop: 'price2',
          align: "center",
          isSlot: true

        }, {
          label: '主治医师',
          prop: 'price3',
          align: "center",
          isSlot: true
        }, {
          label: '住院医师',
          prop: 'price4',
          align: "center",
          isSlot: true
        }, {
          label: '公共卫生执业医师',
          prop: 'price5',
          align: 'center',
          isSlot: true,
        }
      ],
      columnsReCheckTechnician: [//技师
        {
          label: '价格（元）',
          prop: 'priceSku',
          align: "center",
          isSlot: true
        }, {
          label: '主任技师',
          prop: 'price1',
          align: "center",
          isSlot: true

        }, {
          label: '副主任技师',
          prop: 'price2',
          align: "center",
          isSlot: true

        }, {
          label: '主管技师',
          prop: 'price3',
          align: "center",
          isSlot: true
        }, {
          label: '技师',
          prop: 'price4',
          align: "center",
          isSlot: true
        }
      ],
      columnsReCheckDocimaster: [//技师
        {
          label: '价格（元）',
          prop: 'priceSku',
          align: "center",
          isSlot: true
        }, {
          label: '主任检验师',
          prop: 'price1',
          align: "center",
          isSlot: true

        }, {
          label: '副主任检验师',
          prop: 'price2',
          align: "center",
          isSlot: true

        }, {
          label: '主管检验师',
          prop: 'price3',
          align: "center",
          isSlot: true
        }, {
          label: '检验师',
          prop: 'price4',
          align: "center",
          isSlot: true
        }, {
          label: '检验士',
          prop: 'price5',
          align: "center",
          isSlot: true
        }
      ],
      reCheckDoctorList: [],
      reCheckTechnicianList: [],
      reCheckDocimasterList: [],

      columnsMedicine: [
        {
          label: '项目名称',
          prop: 'name',
          align: "center",
          isSlot: true
        }, {
          label: '临床意义',
          prop: 'clinicalWorth',
          align: "center",
          width: 700,
          isSlot: true

        }, {
          label: '图片',
          prop: 'imageUrl',
          align: "center",
          isSlot: true

        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true,
        }
      ],
      columnsMedicineLink: [
        {
          label: '链接标题',
          prop: 'name',
          align: "center",
          isSlot: true
        }, {
          label: '链接',
          prop: 'linkUrl',
          align: "center",
          width: 700,
          isSlot: true

        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true,
        }
      ],
      medicineList: [],
      medicineLinkList: [],
      imageIndex: 0,
      hospitalIndex: 0,
      columnsDoctors: [
        {
          label: '医院名称',
          prop: 'hospitalName',
          align: "center",
        }, {
          label: '是否有医联体单位',
          prop: 'medicalUnionId',
          align: "center",
          formatter: (row, cellValue) => {
            return row.medicalUnionId === 0 ? '没有' : '有'
          },
        }, {
          label: '复核医生',
          prop: 'nickName',
          align: "center",
          isSlot: true,
        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true,
        }
      ],
      detectIndex: 0,
      rules: {
        name: [
          {required: true, message: '请填写分类名称'}
        ],
        healthRiskTypeId: [
          {required: true, message: '请选择所属分类'}
        ],
        imageUrl: [
          {required: true, message: '请填上传列表图片'}
        ],
        detailImageUrl: [
          {required: true, message: '请上传详情图片'}
        ],
        itemList: [
          {required: true, message: '请完善服务选项'}
        ],
        standardService: [
          {required: true, message: '请填写标配服务'}
        ],
        hospitalList: [
          {required: true, message: '请选择服务医院'}
        ],
        rangeContent: [
          {required: true, message: '请输入检测范围'}
        ],
        detectList: [
          {required: true, message: '请完善检测项目列表'}
        ],
        specialNote: [
          {required: true, message: '请填写特别说明'}
        ]
      },

    }
  },
  created() {
    if (this.dataObj) {
      //编辑
      this.title = '编 辑'
      this.submitData.id = this.dataObj.id
      this.getDetail()
      this.searchMethod(null)
    } else {
      //新增
      this.title = '新 增'
    }
    this.getClassification()
    this.getTreeList()
  },
  methods: {
    modalClose() {
      this.$emit('update:visible', false); // 直接修改父组件的属性
    },
    handleOption(op, row, index) {
      switch (op) {
        case 'addItem':
          this.submitData.itemList.push({
            price: '',
            num: '',
            unit: '',
            extendFee: '',
            detectFee: '',
            healthCheckPackageReCheckPriceDtosMap: {},//复核分成
            healthCheckPackageReadPriceDtosMap: {},//分析分成
            detectList: [],//检测项目列表
          })
          this.analyseDoctorList.push({
            priceSku: '',
            price1: '',
            price2: '',
            price3: '',
            price4: '',
            price5: '',
          })
          this.analyseTechnicianList.push({
            priceSku: '',
            price1: '',
            price2: '',
            price3: '',
            price4: '',
          })
          this.analyseDocimasterList.push({
            priceSku: '',
            price1: '',
            price2: '',
            price3: '',
            price4: '',
            price5: '',
          })

          this.reCheckDoctorList.push({
            priceSku: '',
            price1: '',
            price2: '',
            price3: '',
            price4: '',
            price5: '',
          })
          this.reCheckTechnicianList.push({
            priceSku: '',
            price1: '',
            price2: '',
            price3: '',
            price4: '',
          })
          this.reCheckDocimasterList.push({
            priceSku: '',
            price1: '',
            price2: '',
            price3: '',
            price4: '',
            price5: '',
          })
          break
        case 'delItem':
          this.submitData.itemList.splice(row, 1)
          this.analyseDoctorList.splice(row, 1)
          this.analyseTechnicianList.splice(row, 1)
          this.analyseDocimasterList.splice(row, 1)

          this.reCheckDoctorList.splice(row, 1)
          this.reCheckTechnicianList.splice(row, 1)
          this.reCheckDocimasterList.splice(row, 1)

          break
        case 'detectConfig':
          if (row.price && row.num && row.unit) {
            this.showDetectConfigDialog = true
            this.detectListData = row
            this.detectIndex = index
          } else {
            this.$message.error('请先配置服务选项')
          }


          break

        case 'addMedicinel':
          this.medicineList.push({
            name: '',
            clinicalWorth: '',
            imageUrl: '',
            type: 1
          })
          break
        case 'delMedicinel':
          this.medicineList.splice(row, 1)
          break
        case 'addMedicinelLink':
          this.medicineLinkList.push({
            name: '',
            linkUrl: '',
            type: 2
          })
          break
        case 'delMedicinelLink':
          this.medicineLinkList.splice(row, 1)
          break
        case 'editDoctor':
          this.showDoctorDialog = true
          this.doctorData = row
          this.hospitalIndex = index
          break
        case 'submit':
          this.$refs.formModelRef.validate(valid => {
            if (valid) {
              let parse = JSON.parse(JSON.stringify(this.submitData));
              if (!parse.imageUrl) {
                this.$message.error('请上传列表图片')
              } else if (this.detailImageList.length === 0) {
                this.$message.error('请上传详情图片')
              } else if (parse.itemList.length === 0) {
                this.$message.error('请配置服务选项')
              } else {
                if (parse.split === 0 && parse.reCheck === 1){
                  parse.itemList.forEach((item, index) => {
                    //TODO 分析
                    item.healthCheckPackageReadPriceDtosMap[0] = [
                      {
                        price: this.analyseDoctorList[index].price1,
                        doctorTitleId: 3,
                        doctorTitleName: '主任医师',
                      },
                      {
                        price: this.analyseDoctorList[index].price2,
                        doctorTitleId: 4,
                        doctorTitleName: '副主任医师',
                      },
                      {
                        price: this.analyseDoctorList[index].price3,
                        doctorTitleId: 6,
                        doctorTitleName: '主治医师',
                      },
                      {
                        price: this.analyseDoctorList[index].price4,
                        doctorTitleId: 7,
                        doctorTitleName: '住院医师',
                      },
                      {
                        price: this.analyseDoctorList[index].price5,
                        doctorTitleId: 32,
                        doctorTitleName: '公共卫生执业医师',
                      },
                    ]

                    item.healthCheckPackageReadPriceDtosMap[2] = [
                      {
                        price: this.analyseTechnicianList[index].price1,
                        doctorTitleId: 15,
                        doctorTitleName: '主任技师',
                      },
                      {
                        price: this.analyseTechnicianList[index].price2,
                        doctorTitleId: 16,
                        doctorTitleName: '副主任技师',
                      },
                      {
                        price: this.analyseTechnicianList[index].price3,
                        doctorTitleId: 17,
                        doctorTitleName: '主管技师',
                      },
                      {
                        price: this.analyseTechnicianList[index].price4,
                        doctorTitleId: 18,
                        doctorTitleName: '技师',
                      },

                    ]

                    item.healthCheckPackageReadPriceDtosMap[7] = [
                      {
                        price: this.analyseDocimasterList[index].price1,
                        doctorTitleId: 47,
                        doctorTitleName: '主任检验师',
                      },
                      {
                        price: this.analyseDocimasterList[index].price2,
                        doctorTitleId: 48,
                        doctorTitleName: '副主任检验师',
                      },
                      {
                        price: this.analyseDocimasterList[index].price3,
                        doctorTitleId: 49,
                        doctorTitleName: '主管检验师',
                      },
                      {
                        price: this.analyseDocimasterList[index].price4,
                        doctorTitleId: 50,
                        doctorTitleName: '检验师',
                      },
                      {
                        price: this.analyseDocimasterList[index].price5,
                        doctorTitleId: 51,
                        doctorTitleName: '检验士',
                      },
                    ]
                    //TODO 复核
                    item.healthCheckPackageReCheckPriceDtosMap[0] = [
                      {
                        price: this.reCheckDoctorList[index].price1,
                        doctorTitleId: 3,
                        doctorTitleName: '主任医师',
                      },
                      {
                        price: this.reCheckDoctorList[index].price2,
                        doctorTitleId: 4,
                        doctorTitleName: '副主任医师',
                      },
                      {
                        price: this.reCheckDoctorList[index].price3,
                        doctorTitleId: 6,
                        doctorTitleName: '主治医师',
                      },
                      {
                        price: this.reCheckDoctorList[index].price4,
                        doctorTitleId: 7,
                        doctorTitleName: '住院医师',
                      },
                      {
                        price: this.reCheckDoctorList[index].price5,
                        doctorTitleId: 32,
                        doctorTitleName: '公共卫生执业医师',
                      },
                    ]

                    item.healthCheckPackageReCheckPriceDtosMap[2] = [
                      {
                        price: this.reCheckTechnicianList[index].price1,
                        doctorTitleId: 15,
                        doctorTitleName: '主任技师',
                      },
                      {
                        price: this.reCheckTechnicianList[index].price2,
                        doctorTitleId: 16,
                        doctorTitleName: '副主任技师',
                      },
                      {
                        price: this.reCheckTechnicianList[index].price3,
                        doctorTitleId: 17,
                        doctorTitleName: '主管技师',
                      },
                      {
                        price: this.reCheckTechnicianList[index].price4,
                        doctorTitleId: 18,
                        doctorTitleName: '技师',
                      },

                    ]

                    item.healthCheckPackageReCheckPriceDtosMap[7] = [
                      {
                        price: this.reCheckDocimasterList[index].price1,
                        doctorTitleId: 47,
                        doctorTitleName: '主任检验师',
                      },
                      {
                        price: this.reCheckDocimasterList[index].price2,
                        doctorTitleId: 48,
                        doctorTitleName: '副主任检验师',
                      },
                      {
                        price: this.reCheckDocimasterList[index].price3,
                        doctorTitleId: 49,
                        doctorTitleName: '主管检验师',
                      },
                      {
                        price: this.reCheckDocimasterList[index].price4,
                        doctorTitleId: 50,
                        doctorTitleName: '检验师',
                      },
                      {
                        price: this.reCheckDocimasterList[index].price5,
                        doctorTitleId: 51,
                        doctorTitleName: '检验士',
                      },
                    ]
                  })
                }


                parse.loreList = this.medicineList.concat(this.medicineLinkList)
                let parseImages = JSON.parse(JSON.stringify(this.detailImageList));
                parse.detailImageUrl = JSON.stringify(parseImages.map(item => item.url))


                this.post(this.api.cooperationHospital.healthCheckManageuploadInfo, parse).then((res) => {
                  if (res.data.code === '200') {
                    this.$message.success('操作成功')
                    this.modalClose()
                    this.$parent._getList()
                  }
                })
              }

            }
          })

          break
      }
    },
    //接收子组件参数
    handleResultList(data) {
      this.$set(this.submitData.hospitalList[this.hospitalIndex], 'doctorDtos', data)
    },
    handleResultDetect(data) {
      this.$set(this.submitData.itemList[this.detectIndex], 'detectList', data)
    },
    //更改服务选项，拆分情况变化
    hadnleInput() {

      this.submitData.itemList.forEach((item, index) => {
        this.$set(this.analyseDoctorList[index], 'priceSku', (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''));
        this.$set(this.analyseTechnicianList[index], 'priceSku', (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''));
        this.$set(this.analyseDocimasterList[index], 'priceSku', (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''));

        this.$set(this.reCheckDoctorList[index], 'priceSku', (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''));
        this.$set(this.reCheckTechnicianList[index], 'priceSku', (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''));
        this.$set(this.reCheckDocimasterList[index], 'priceSku', (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''));
        this.$forceUpdate()
      })

    },
    //搜索医院
    searchMethod(query) {
      if (query !== '') {
        this.searchLoading = true; // 锁住
        this.post(this.api.cooperationHospital.getServiceHospitalList, {
          searchCondition: query,
          pageIndex: 0,
          pageSize: 100
        }).then(res => {
          if (res.data.code === '200') {
            this.searchLoading = false;
            this.hospitals = res.data.object;
            this.hospitals.forEach(item=>{
              this.$set(item,'hospitalName',item.name)
            })
          }
        })
      } else {
        this.hospitals = [];
      }
    },
    // 所属分类
    getClassification() {
      this.post(this.api.cooperationHospital.healthRiskTypegetPageList, {
        pageIndex: 0,
        pageSize: 100
      }).then(res => {
        if (res.data.code === '200') {
          this.healthRiskTypeList = res.data.object;
        }
      })
    },
    //查询慢病病种
    getTreeList() {
      this.post(this.api.promote.getTreeList, {
        pageIndex: 0,
        pageSize: 100
      }).then(res => {
        if (res.data.code === '200') {
          this.slowList = res.data.object;
        }
      })
    },
    // 获取详情
    getDetail() {
      this.post(this.api.cooperationHospital.healthCheckManagegetDetail, {
        id: this.dataObj.id
      }).then((res) => {
        if (res.data.code === '200') {
          this.submitData = Object.assign(this.submitData, res.data.object)
          this.detailImageList = JSON.parse(this.submitData.detailImageUrl)
          this.detailImageList = this.detailImageList.map(item => ({
            url: item
          }))
          this.submitData.hospitalList.forEach(item => {
            this.$set(item, 'name', item.hospitalName)
          })

          if (this.submitData.loreList && this.submitData.loreList.filter(item => item.type == 1)) {
            this.medicineList = this.submitData.loreList.filter(item => item.type == 1)
          } else {
            this.medicineList = []
          }
          if (this.submitData.loreList && this.submitData.loreList.filter(item => item.type == 2)) {
            this.medicineLinkList = this.submitData.loreList.filter(item => item.type == 2)
          } else {
            this.medicineLinkList = []
          }
          this.submitData.healthCheckPackageThemes = this.submitData.healthCheckPackageThemes.filter(item => item)
          this.defaultCheckedKeys = this.submitData.healthCheckPackageThemes.map(item => item.themeId)
          if (this.submitData.split === 0 && this.submitData.reCheck === 1){
            this.submitData.itemList.forEach(item => {
              this.analyseDoctorList.push({
                priceSku: (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''),
                price1: item.healthCheckPackageReadPriceDtosMap[0][0].price,
                price2: item.healthCheckPackageReadPriceDtosMap[0][1].price,
                price3: item.healthCheckPackageReadPriceDtosMap[0][2].price,
                price4: item.healthCheckPackageReadPriceDtosMap[0][3].price,
                price5: item.healthCheckPackageReadPriceDtosMap[0][4].price,
              })
              this.analyseTechnicianList.push({
                priceSku: (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''),
                price1: item.healthCheckPackageReadPriceDtosMap[2][0].price,
                price2: item.healthCheckPackageReadPriceDtosMap[2][1].price,
                price3: item.healthCheckPackageReadPriceDtosMap[2][2].price,
                price4: item.healthCheckPackageReadPriceDtosMap[2][3].price,
              })
              this.analyseDocimasterList.push({
                priceSku: (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''),
                price1: item.healthCheckPackageReadPriceDtosMap[7][0].price,
                price2: item.healthCheckPackageReadPriceDtosMap[7][1].price,
                price3: item.healthCheckPackageReadPriceDtosMap[7][2].price,
                price4: item.healthCheckPackageReadPriceDtosMap[7][3].price,
                price5: item.healthCheckPackageReadPriceDtosMap[7][4].price,
              })


              this.reCheckDoctorList.push({
                priceSku: (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''),
                price1: item.healthCheckPackageReCheckPriceDtosMap[0][0].price,
                price2: item.healthCheckPackageReCheckPriceDtosMap[0][1].price,
                price3: item.healthCheckPackageReCheckPriceDtosMap[0][2].price,
                price4: item.healthCheckPackageReCheckPriceDtosMap[0][3].price,
                price5: item.healthCheckPackageReCheckPriceDtosMap[0][4].price,
              })
              this.reCheckTechnicianList.push({
                priceSku: (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''),
                price1: item.healthCheckPackageReCheckPriceDtosMap[2][0].price,
                price2: item.healthCheckPackageReCheckPriceDtosMap[2][1].price,
                price3: item.healthCheckPackageReCheckPriceDtosMap[2][2].price,
                price4: item.healthCheckPackageReCheckPriceDtosMap[2][3].price,
              })
              this.reCheckDocimasterList.push({
                priceSku: (item.price || '') + '元' + '/' + (item.num || '') + ((item.unit == 1 ? '小时' : '次') || ''),
                price1: item.healthCheckPackageReCheckPriceDtosMap[7][0].price,
                price2: item.healthCheckPackageReCheckPriceDtosMap[7][1].price,
                price3: item.healthCheckPackageReCheckPriceDtosMap[7][2].price,
                price4: item.healthCheckPackageReCheckPriceDtosMap[7][3].price,
                price5: item.healthCheckPackageReCheckPriceDtosMap[7][4].price,
              })



            })
          }

        }
      })
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!');
      }
      return isLt2M;
    },
    uploadLogoSuccess(res) {
      this.submitData.imageUrl = res.object[0];
    },
    handleIndex(index) {
      this.imageIndex = index
    },
    uploadMedicineSuccess(res) {
      this.medicineList[this.imageIndex].imageUrl = res.object[0];
    },
    handlePictureCardPreview(res) {
      this.detailImageList.push({url: res.object[0]});
    },
    onexceed() {
      this.$message.warning('详情图片至多上传6张');
    },
    // 是否是重点合作医院 多选
    checkboxItem(value, index, item) {
      this.submitData.hospitalList.forEach(hItem => {
        if (hItem.hospitalId === item.hospitalId) {
          hItem.emphasisHospital = value ? 1 : 0;
        }
      })
    },
    handleCheckChange(obj, selectObj) {
      let checkedNodes = selectObj.checkedKeys;
      checkedNodes = checkedNodes.filter(item => item)
      this.submitData.healthCheckPackageThemes = checkedNodes.map(item => ({
        themeId: item
      }))
    },
    onremove(res, list) {
      if (res.response) {
        this.detailImageList = this.detailImageList.filter(ele => ele != res.response.object[0]);
      } else {
        this.detailImageList = this.detailImageList.filter(ele => ele.url != res.url);
      }

    },
  },
  components: {
    'element-table': ElementTable,
    'doctor-dialog': editDorctorDialog,
    'detect-dialog': detectConfigDialog,
  }
}
</script>

<style scoped>
/deep/ .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 5px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

/*.avatar-uploader-icon {*/
/*  font-size: 28px;*/
/*  color: #8c939d;*/
/*  width: 178px;*/
/*  height: 178px;*/
/*  line-height: 178px;*/
/*  text-align: center;*/
/*}*/

.avatar {
  width: 148px;
  height: 148px;
  display: block;
}
</style>
